package com.cyh.StaticDispatch_DinamicDispatch;

/**
 * Created by yanhuche on 3/20/2017.
 */
public class DynamicDispatch {

    static abstract class Human {
        protected abstract void sayHello();
    }

    static class Man extends Human {
        @Override
        protected void sayHello() {
            System.out.println("man say hello");
        }
    }

    static class Woman extends Human {
        @Override
        protected void sayHello() {
            System.out.println("woman say hello");
        }
    }

    public static void main(String[] args) {
        Human man = new Man();
        Human woman = new Woman();
        man.sayHello();
        woman.sayHello();
        man = new Woman();
        man.sayHello();
    }
}

/**
 * JVM如何选择多态的方法？
 * invokevirtual指令的多态查找过程，指令的第一步就是在运行期确定接收者的实际类型。
 *
 *
 * 动态分配。
 *
 * 重写。
 */

